package javax.realtime;

public class PeriodicParameters extends ReleaseParameters implements Cloneable {

	private HighResolutionTime start;
	private RelativeTime period;
	
	public PeriodicParameters(HighResolutionTime start, RelativeTime period)
	{
		this(start, period, null, null, null, null);
	}
	public PeriodicParameters(HighResolutionTime start, RelativeTime period, RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler)
	{
		//(RelativeTime cost, RelativeTime deadline, AsyncEventHandler overrunHandler, AsyncEventHandler missHandler)
		super(cost, deadline, overrunHandler, missHandler);
		if(start == null) start = new RelativeTime(0, 0);
		//if(!start.equals(new RelativeTime(0,0))) throw new IllegalArgumentException("This implementation dose not support start time reservation");
		if(period == null) throw new IllegalArgumentException();
		this.start = start;
		this.period = period;
	}
	public PeriodicParameters(RelativeTime period)
	{
		this(null, period, null, null, null, null);
	}
	
	public RelativeTime getPeriod()
	{
		return period;
	}
	public HighResolutionTime getStart()
	{
		return start;
	}
	public void setDeadline(RelativeTime deadline)
	{
		if(deadline == null) deadline = period;
		super.setDeadline(deadline);
	}
	public boolean setIfFeasible(RelativeTime period, RelativeTime cost, RelativeTime deadline)
	{
		if(period == null) throw new IllegalArgumentException();
		if(period.getMilliseconds() < 0 || period.getNanoseconds() < 0 || (period.getMilliseconds() == 0 && period.getNanoseconds() == 0)) throw new IllegalArgumentException();
		if(cost == null) cost = new RelativeTime(0, 0);
		if(cost.getMilliseconds() < 0 || cost.getNanoseconds() < 0) throw new IllegalArgumentException();
		if(deadline == null) deadline = period;
		if(deadline.getMilliseconds() < 0 || deadline.getNanoseconds() < 0 || (deadline.getMilliseconds() == 0 && deadline.getNanoseconds() == 0)) throw new IllegalArgumentException();
		
		setPeriod(period);
		setCost(cost);
		setDeadline(deadline);
		return true;
	}
	public void setPeriod(RelativeTime period)
	{
		if(period == null) throw new IllegalArgumentException();
		if(period.getMilliseconds() < 0 || period.getNanoseconds() < 0 || (period.getMilliseconds() == 0 && period.getNanoseconds() == 0)) throw new IllegalArgumentException();
		this.period = period;
	}
	public void setStart(HighResolutionTime start)
	{
		if(start == null) start = new RelativeTime(0, 0);
		this.start = start;
	}
}
